package Flightdizhu;

import java.util.*;

public class DouDizhu {
    public static void main(String[] args) {
        /**
         * 1.组装牌
         * 集合 map list
         */
        HashMap<Integer, String> poker = new HashMap<>();
        ArrayList<Integer> pokerIndex = new ArrayList<>();

        List<String> numbers = Arrays.asList("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "k", "A");
        List<String> colors = Arrays.asList("♥", "♠", "♣", "♦");

        int index = 0;
        poker.put(index, "大王");
        pokerIndex.add(index);
        index++;

        poker.put(index, "小王");
        pokerIndex.add(index);
        index++;


        for (String number : numbers) {
            for (String color : colors) {
                poker.put(index, number + color);
                pokerIndex.add(index);
                index++;
            }
        }
        //2.洗牌
        Collections.shuffle(pokerIndex);
        //System.out.println("pokerIndex = " + pokerIndex);
        //System.out.println("poker = " + poker);

        //3.发牌
        ArrayList<Integer> play1 = new ArrayList<>();
        ArrayList<Integer> play2 = new ArrayList<>();
        ArrayList<Integer> play3 = new ArrayList<>();
        ArrayList<Integer> di = new ArrayList<>();

        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer in = pokerIndex.get(i);
            if (i >= 51) {
                di.add(in);
            } else if (i % 3 == 0) {
                play1.add(in);
            } else if (i % 3 == 1) {
                play2.add(in);
            } else if (i % 3 == 2) {
                play3.add(in);
            }
        }
        //整理
        Collections.sort(play1);
        Collections.sort(play2);
        Collections.sort(play3);
        //看牌
        show("1",poker,play1);
        show("2",poker,play2);
        show("3",poker,play3);
        show("di",poker,di);
    }



    public static void show(String name, HashMap<Integer, String> poker, ArrayList<Integer> list) {
        System.out.println(name + ":");
        for (Integer key : list) {
            String s = poker.get(key);
            System.out.print("s = " + s);
        }
        System.out.println();
    }
}
